<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户申请记录</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function cheackAll(obj){
			var isCheck = $(obj).is(":checked");

			$("#contentTable").find("input[type='checkbox']").each(function(){
				$(this).prop("checked", isCheck);
			});
		}
		function batchProcesst(flag){
			if(flag == 'delete'){
			var currentSelect = $("#delFlag").val();
					if(currentSelect != 3){
						 alertx("<spring:message code='tips.deldismissal' />");
						 return;
					}
			}
			var msg = "";
			if (flag == 'pass') { msg = "<spring:message code='tips.allpass' />" }
			else if (flag == 'reject') { msg = "<spring:message code='tips.alldismissal' />" }

            confirmx(msg, function () {
                var groupList = "";
                $("#contentTable").find("input[type='checkbox']").each(function () {
                    if ($(this).prop('checked')) {
                        var egId = $(this).attr("id");
                        groupList = groupList + "'" + egId + "',";
                    }
                });
                $.ajax({
                    type: "POST",
                    url: "${ctx}/sys/user/checkUser",
                    data: {userList: groupList, flag: flag},
                    datatype: "json",
                    success: function (data) {
                        alertx(data.msg, function () {
                            window.location.reload();
                        });
                    },
                    error: function (e) {
                        alertx("<spring:message code='tips.contactadmin' />");
                        console.log(e);
                    }
                });
            });
		}
		function batchDelete(){
			var msg = "<spring:message code='tips.delall' />";

            confirmx(msg, function () {
                var groupList = "";
                $("#contentTable").find("input[type='checkbox']").each(function () {
                    if ($(this).prop('checked')) {
                        var egId = $(this).attr("id");
                        groupList = groupList + "'" + egId + "',";
                    }
                });
                $.ajax({
                    type: "POST",
                    url: "${ctx}/sys/user/batchdelete",
                    data: {userList: groupList, type: 'apply'},
                    datatype: "json",
                    success: function (data) {
                        alertx(data.msg, function () {
                            window.location.reload();
                        });
                    },
                    error: function (e) {
                        alertx("<spring:message code='tips.contactadmin' />");
                        console.log(e);
                    }
                });
            });
		};
		function resubmit(){
			var currentSelect = $("#delFlag").val();
			if(currentSelect != 3){
				 alertx("<spring:message code='tips.dismissal' />");
				 return;
				}
			
			var groupList = "";
            $("#contentTable").find("input[type='checkbox']").each(function () {
                if ($(this).prop('checked')) {
                    var egId = $(this).attr("id");
                    groupList = groupList + "'" + egId + "',";
                }
            });
            $.ajax({
                type: "POST",
                url: "${ctx}/sys/user/resubmit",
                data: {userList: groupList},
                datatype: "json",
                success: function (data) {
                    alertx(data.msg, function () {
                        window.location.reload();
                    });
                },
                error: function (e) {
                    alertx("<spring:message code='tips.contactadmin' />");
                    console.log(e);
                }
            });
		};
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/user/applylist?flag=false"><spring:message code="menu.user.Application_Record"/></a></li>
	</ul>
	<div class="control-group" style="margin-bottom:20px;/*background-color:#f5f5f5;*/" >
		<input type="button" value="<spring:message code='Batch.deletion'/>" class="btn btn-default btn-lg" onclick="batchDelete();">
		<input type="button" value="<spring:message code='common.resubmit'/>" class="btn btn-default btn-lg" onclick="resubmit();">
		
	<form:form id="searchForm" modelAttribute="user" action="${ctx}/sys/user/applylist" method="post" class="breadcrumb form-search"  style="float:right;padding-bottom:0px;padding-top:0px;">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input name="flag" type="hidden" value="${flag}">
		<input name="isFirst" type="hidden" value="${isFirst}">
		<ul class="ul-form">
            <li><label><spring:message code="common.account"/>/<spring:message code="common.name"/>：</label>
                <form:input path="loginName" htmlEscape="false" maxlength="200" class="input-medium"/>
            </li>
			<li><label><spring:message code='common.status'/>：</label>
                <form:select path="delFlag" htmlEscape="false"  class="input-medium">
                    <form:option value="5"><spring:message code="all"/></form:option>
                    <form:option value="0"><spring:message code="approved"/></form:option>
                    <form:option value="1"><spring:message code='common.delete'/></form:option>
                    <form:option value="2"><spring:message code='inapproval'/></form:option>
                    <form:option value="3"><spring:message code="rejected"/></form:option>
                </form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.Query'/>"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	</div>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
			<th style="width:40px;text-align:center;"><input type="checkbox" onclick="cheackAll(this)"/></th>
				<th><spring:message code="common.account"/></th>
				<th><spring:message code="common.name"/></th>
                <th><spring:message code="common.group.branchoffice"/></th>
                <th><spring:message code="common.phone_number"/></th>
                <th><spring:message code="common.authority"/></th>
                <th><spring:message code="common.applicant"/></th>
                <th><spring:message code="common.applicant.time"/></th>
				<th>
					<c:if test="${flag}">
						<spring:message code='common.applicant'/>
					</c:if>
					<c:if test="${!flag}">
						<spring:message code='common.approver'/>
					</c:if>
				</th>
				<th><spring:message code='common.approver.time'/></th>
                <th><spring:message code='audit.state'/></th>
				<th><spring:message code='common.comment'/></th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="user">
			<tr>
			<td style="text-align:center;">
					<c:if test="${user.id != '1' and user.id != 'u_1'}">
						<input type="checkbox" id="${user.id}"/>
					</c:if>
				</td>	
				<td><a href="${ctx}/sys/user/info?id=${user.id}&showtype=2">
					${user.loginName}
				</a></td>
				<td> ${user.name} </td>
				<td> ${user.company.name} </td>
                <td> ${user.mobile} </td>
                <td> ${user.role.name} </td>
               <td> ${user.createBy.name} </td>
                <td> <fmt:formatDate value="${user.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
                <td>${flag?user.createBy.name:user.checkBy.name}</td>
                <td> <fmt:formatDate value="${user.checkDate}" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
				<td>
                    <c:if test="${user.delFlag == '0'}">
                        <spring:message code="approved"/>
                    </c:if>
                    <c:if test="${user.delFlag == '1'}">
                        <spring:message code='common.delete'/>
                    </c:if>
                    <c:if test="${user.delFlag == '2'}">
                        <spring:message code='inapproval'/>
                    </c:if>
                    <c:if test="${user.delFlag == '3'}">
                        <spring:message code="rejected"/>
                    </c:if>
                </td>
				<td>${user.comment}</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>